//index.js
import api from '../../tool/requestModel.js'
Page({
	data: {
		// 当前列表默认值
		currentID: 0,
		// 是否显示全部列表
		shouqi: true,
		// 顶部列表数据
		goodList: [],
		indexDetail: [],
		isTitleShow: false
	},
	onLoad: function(option) {
        console.log(option)
		this.setData({
			currentID: option.id,
			isTitleShow: option.show
		})
		if (!option.time) {
			this.requestDetail(option.id)
		}
		// console.log(option)
		if (option.time == 1) {
			api.reDuDetail()
				.then(res => {
					this.setData({
						indexDetail: res.data
					})
				})
		} else if (option.time == 2) {
			api.zongTuijian()
				.then(res => {
					this.setData({
						indexDetail: res.data
					})
				})
		}
	},
	onShow() {
		if (this.data.isTitleShow) {
			return
		}
		this.requestDetail(this.data.currentID)
	},
	// 列表点击事件
	liebiaoClick:function(e) {
		let index = e.currentTarget.dataset.id
		this.setData({
			currentID: index
		})
		this.requestDetail(index)
	},
	shouBtn:function() {
		this.setData({
			shouqi: !this.data.shouqi
		})
	},
	requestDetail: function(id) {
        let that = this
		api.lieBiaoDetail({
				category_id: id
			})
			.then(resp => {
                console.log(resp)
                let boxListDetail = resp.data.Product
                boxListDetail.forEach(el => {
                    el.jinri_fangwen = that.futerPeope(el.jinri_fangwen)
                })
				that.setData({
					goodList: resp.data.Product_Category,
					indexDetail: boxListDetail
				})
			})
	},
    futerPeope: function(numbers) {
			// console.log(numbers)
			return numbers > 10000 ? (numbers / 10000).toFixed(2) + '万' : numbers
		},
		// 更多点击事件
		liebiaoBtn: function() {
			tt.navigateTo({
				url: '../../pages/liebiao/liebiao?show=' + true + '&time=' + this.data.stule,
			})
		},
		ljcsDetail: function(e) {
			let item = e.currentTarget.dataset.item
			if (this.data.isshow) {
				tt.redirectTo({
					url: '../../pages/ljcs/ljcs?id=' + item.id,
				})
				return
			}
			tt.navigateTo({
				url: '../../pages/ljcs/ljcs?id=' + item.id,
			})
		}
})
